<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>添加员工</h1>
<form action="">
    <input type="text" name="name" v-model="name" placeholder="姓名">
    <input type="text" name="job" v-model="job" placeholder="工作">
    <input type="text" name="sal" v-model="sal" placeholder="工资">
    <input type="button" value="添加" @click="add()">
</form>
<!--引入axios和vue-->
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script>
    let v = new Vue({
        el:"form",
        data:{name:"",
              job:"",
              sal:""
        },
        methods:{
            add:function () {
                //let data = new FormData(document.querySelector("form"));
                /*axios.post("/add",data).then(function (res) {
                    if(res.data==1){
                        location.href="/";
                    }else{
                        alert("添加失败");
                    }
                })*/
                $.post(
                    "/add",
                    {"name":v.name,"job":v.job,"sal":v.sal},
                    function(result){
                        if(result==1){
                            location.href="/";
                        }else{
                            alert("添加失败");
                        }
                    });
            }
        }

    })

</script>
</body>
</html>